import {
  getConfigList,
  editConfigList
} from '@/api/system'

const state = {
  parameterData: [],
  parameterDataCount: 0
}

const mutations = {
  GET_PARAMETER_DATA: (state, data) => {
    state.parameterData = data
  },
  GET_PARAMETER_DATA_COUNT: (state, data) => {
    state.parameterDataCount = data
  }
}

const actions = {
  async getParameterData({ commit }, playload) {
    let data = {}
    let newData = []
    if (Object.keys(playload).length > 0) {
      data = playload
    }
    const resp = await getConfigList(data)
    resp.data.data.map((item) => {
      newData = [...newData, {
        id: item.id,
        key0: item.key0,
        value: item.value,
        des: item.des
      }]
    })
    commit('GET_PARAMETER_DATA', newData)
    // commit('GET_PARAMETER_DATA_COUNT', newData.length)
    return resp
  },
  async editParameterData({ commit }, playload) {
    const resp = await editConfigList(playload)
    return resp
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
